// 添加按钮操作
$('#button-add').click(function(){
    var url = scope.add_url;
    window.location.href = url;
});
// 提交form表单操作
$('#singcms-button-submit').click(function(){
    var data = $('#singcms-form').serializeArray();
    postData = {};
    $(data).each(function(i){
        postData[this.name] = this.value;
    });
    url = scope.save_url;
    jump_url = scope.jump_url;
    // console.log(url);return;
    $.post(url,postData,function(result){
        if(result.status == 1){
            return dialog.success(result.message,jump_url)
        }else if(result.status == 0){
            return dialog.error(result.message);
        }
    },"JSON");
});
// 编辑模型
$('.singcms-table #singcms-edit').on('click',function(){
    var id = $(this).attr('attr-id');
    url = scope.edit_url+'?id='+id;
    window.location.href = url;
});
// 删除操作JS
$('.singcms-table #singcms-delete').on('click',function(){
    var id = $(this).attr('attr-id');
    var a = $(this).attr('attr-a');
    var message = $(this).attr('attr-message');
    var url = scope.set_status_url;
    data = {};
    data['id'] = id;
    data['status'] = -1;
    layer.open({
        type : 0,
        tutle : '是否提交？',
        btn : ['yes','no'],
        icon : 3,
        closeBtn : 2,
        content : '是否确定'+message,
        scrollbar : true,
        yes:function(){
            todelete(url,data);
        },
    });
});
function todelete(url,data){
    $.post(url,data,function(s){
            if(s.status == 1){
                return dialog.success(s.message,'');
            }else{
                return dialog.error(s.message);
            }
        }
    ,"JSON");
}
//排序操作
$('#button-listorder').click(function(){
    var data = $('#singcms-listorder').serializeArray();
    postData = {};
    $(data).each(function(i){
        postData[this.name] = this.value;
    });
    var url = scope.listorder_url;
    $.post(url,postData,function(result){
        if(result.status == 1){
            return dialog.success(result.message,result['data']['jump_url']);
        }else if(result.status ==0){
            return dialog.error(result.message,result['data']['jump_url']);
        }
    },"JSON");
});
// 修改状态
$('.singcms-table #singcms-on-off').on('click',function(){
    var id = $(this).attr('attr-id');
    var status = $(this).attr("attr-status");
    var url = scope.set_status_url;
    // alert(url);return;
    data = {};
    data['id'] = id;
    data['status'] = status;
    layer.open({
        type : 0,
        title : '是否提交？',
        btn : ['yes','no'],
        icon : 3,
        closeBtn : 2,
        content : "是否确定更新状态",
        scrollbar : true,
        yes :function(){
            todelete(url,data);
        },
    });
});
// 推送JS相关
$("#singcms-push").click(function(){
    var id = $("#select-push").val();
    if(id == 0){
        return dialog.error('请选择推荐位');
    }
    push = {};
    postData = {};
    $("input[name='pushcheck']:checked").each(function(i){
        push[i] = $(this).val();
    });
    postData['push'] = push;
    postData['position_id'] = id;
    var url = scope.push_url;
    $.post(url,postData,function(result){
        if(result.status == 1){
            return dialog.success(result.message,result['data']['jump_url']);
        }
        if(result.status == 0){
            return dialog.error(result.message);
        }
    },"JSON");
});